package org.zero.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Zero
 */
public class MyInterceptor1 implements HandlerInterceptor {
    /**
     * 拦截器预处理方法：
     * true：放行（如果有拦截器链，则执行下一个拦截器，反之，执行controller中的方法）
     * false：不放行
     *
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("拦截器进行拦截了111");
        return true;
    }

    /**
     * 拦截器后处理方法：
     * controller方法执行后，跳转页面之前执行
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("拦截器后处理方法执行了111");
    }

    /**
     * 拦截器最终方法：（一般用于释放资源，处理错误等等）
     * 跳转页面之后执行
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("拦截器最终方法执行了111");
    }
}
